import {bizDict} from '/@/stores/bizDict';
import {getByCode} from "/@/api/platform/digital/basDicSet";

/**
 * 获取字典数据
 */
export function useBizDict(...args: any): any {
    const res = ref({});
    return (() => {
        args.forEach((dictType: string) => {
            // @ts-ignore
            res.value[dictType] = [];
            const dicts = bizDict().getDict(dictType);
            if (dicts) {
                // @ts-ignore
                res.value[dictType] = dicts;
            } else {
                getByCode(dictType).then((resp) => {
                    // @ts-ignore
                    res.value[dictType] = resp.data?.basDicItemList;
                    // @ts-ignore
                    bizDict().setDict(dictType, res.value[dictType]);
                });
            }
        });
        return toRefs(res.value);
    })();
}
